#!/usr/bin/python

# Head ends here

import random
DIM = 20

def next_move(player, dr, cop1, cop2, cop3):
	if player == 'R':
		# Robber move
		# Frank en Sander. Hier proggen
		robber_move(dr, cop1, cop2, cop3)
	else:
		# Cop1 move
		cops_move(cop1, cop2, cop3, dr)

def cops_move(cop1, cop2, cop3, dr):
	cop1close = distanceCop(cop1, dr) < 3
	cop2close = distanceCop(cop2, dr) < 3
	cop3close = distanceCop(cop3, dr) < 3		

	if cop1close == True and cop2close == True and cop3close == True:
		if distanceCop(cop1, dr) == 1:
			moves = oneCopNextToDrMoves(cop1, cop2, cop3, dr)
			printMoves(moves[0], moves[1], moves[2])
		elif distanceCop(cop2, dr) == 1:
			moves = oneCopNextToDrMoves(cop2, cop1, cop3, dr)
			printMoves(moves[1], moves[0], moves[2])
		elif distanceCop(cop3, dr) == 1:
			moves = oneCopNextToDrMoves(cop3, cop1, cop2, dr)
			printMoves(moves[1], moves[2], moves[0])
		else:
			moves = dijkstraMoves((cop1, cop2, cop3), dr)
			printMoves(moves[0], moves[1], moves[2])
	else:
		if cop1 == cop2 or cop2 == cop3 or cop1 == cop3:
			moves = dijkstraMoves((cop1, cop2, cop3), dr)
		else:
			moves = collaborativeDiffusionMoves(cop1, cop2, cop3, dr)
		printMoves(moves[0], moves[1], moves[2])

def collaborativeDiffusionMoves(cop1, cop2, cop3, dr):
	cops = (cop1, cop2, cop3)
	cells = []
	for cop in cops:
		field = Field(DIM, DIM)
		field.set(Robber(dr[0], dr[1]))
		for tempCop in cops:
			if tempCop != cop:
				field.set(Cop(tempCop[0], tempCop[1]))
		for x in range(DIM):
			for y in range(DIM):
				field.cells[x][y].heat += 32
		field.diffuse2()
		cells.append(field.moveCop(cop))
	moves1 = (cells[0].x, cells[0].y)
	moves2 = (cells[1].x, cells[1].y)
	moves3 = (cells[2].x, cells[2].y)
	return (moves1, moves2, moves3)
	
def oneCopNextToDrMoves(closeCop, otherCop1, otherCop2, dr):
	cop2 = otherCop1
	cop3 = otherCop2
	pathCop1 = dr
	pathCop2 = None
	pathCop3 = None
	robberMoves = availableMovesRobber(dr)
	robberDiagonalMoves = []
	for i in ((dr[0] - 1, dr[1] - 1), (dr[0] - 1, dr[1] + 2), (dr[0] + 2, dr[1] - 1), (dr[0] + 2, dr[1] + 2)):
		if i in robberMoves:
			robberDiagonalMoves.append(i)
	for i in robberDiagonalMoves:
		if distanceCop(cop2, i) == 1:
			pathCop2 = i
			break
	for i in robberDiagonalMoves:
		if distanceCop(cop3, i) == 1 and i != pathCop2:
			pathCop3 = i
			break
	if pathCop2 == None:
		for i in robberMoves:
			if distanceCop(cop2, i) == 1 and i != pathCop3:
				pathCop2 = i
				break
	if pathCop3 == None:
		for i in robberMoves:
			if distanceCop(cop3, i) == 1 and i != pathCop2:
				pathCop3 = i
				break
	if pathCop2 == None:
		dijkstraCop2 = dijkstra(cop2[0], cop2[1], dr[0], dr[1])
		pathCop2 = dijkstraCop2[0]
	if pathCop3 == None:
		dijkstraCop3 = dijkstra(cop3[0], cop3[1], dr[0], dr[1])
		pathCop3 = dijkstraCop3[0]
	return (pathCop1, pathCop2, pathCop3)

def dijkstraMoves(cops, dr):
	pathCops = []
	for cop in cops:
		dijkstraCop = dijkstra(cop[0], cop[1], dr[0], dr[1])
		pathCops.append(dijkstraCop[0])
	return tuple(pathCops)

def availableMovesRobber(dr):
	result = []
	for i in range(dr[0] - 1, dr[0] + 2):
		for j in range(dr[1] - 1, dr[1] + 2):
			if 0 <= i < DIM and 0 <= j < DIM:
				result.append((i, j))
	return result

def distanceCop(pos1, pos2):
	return abs(pos1[0] - pos2[0]) + abs(pos1[1] - pos2[1])

def printMoves(pathCop1, pathCop2, pathCop3):
	cop1str = str(pathCop1[0]) + " " + str(pathCop1[1])
	cop2str = str(pathCop2[0]) + " " + str(pathCop2[1])
	cop3str = str(pathCop3[0]) + " " + str(pathCop3[1])
	print cop1str + " " + cop2str + " " + cop3str

# Geeft een lijst met tuples in de vorm (x,y) terug met het kortste path van (startX,startY) naar (endX,endY)
# Dit zonder schuine zetten, dus alleen voor de Cops
def dijkstra(startX, startY, endX, endY):
	path = [[0 for i in range(DIM)] for j in range(DIM)]
	currentList = []
	currentList.append((startX, startY, []))
	while len(currentList) != 0:
		newList = []
		for v in currentList:
			x = v[0]
			y = v[1]
			pathList = v[2]
			for i, j in ((x - 1, y), (x + 1, y), (x, y + 1), (x, y - 1)):
				if 0 <= i < DIM and 0 <= j < DIM and path[i][j] == 0:
					if i == endX and j == endY:
						pathList.append((i, j))
						return pathList
					elif path[i][j] == 0:
						newPathList = list(pathList)
						newPathList.append((i, j))
						newList.append((i, j, newPathList))
						path[i][j] = 1
		currentList = newList
		random.shuffle(currentList)
	return None

def robber_move(dr, c1, c2, c3):
	field = Field(DIM, DIM)

	field.set(Robber(dr[0], dr[1]))
	field.set(Cop(c1[0], c1[1]))
	field.set(Cop(c2[0], c2[1]))
	field.set(Cop(c3[0], c3[1]))

	field.diffuse()
	cell = field.move()
	print '{0:d} {0:d}'.format(cell.x, cell.y)

class Cell:
	def __init__(self, x, y):
		self.x = x
		self.y = y
		self.heat = 0.0

class Robber(Cell):
	pass

class Cop(Cell):
	pass

class Field:
	def __init__(self, size_x, size_y):
		self.size_x = size_x
		self.size_y = size_y
		self.robber = None
		self.cops = []
		self.cells = [[0 for x in xrange(self.size_x)] for y in xrange(self.size_y)]

		self.initialize()

	def initialize(self):
		for x in xrange(self.size_x):
			for y in xrange(self.size_y):
				self.set(Cell(x, y))

	def show(self):
		for x in xrange(self.size_x):
			for y in xrange(self.size_y):
				inst = self.get(x, y)
				if isinstance(inst, Robber):
					print 'R',
				elif isinstance(inst, Cop):
					print 'C',
				else:
					print ' ',

				if y == self.size_y - 1:
					print ''

	def get(self, x, y):
		if x < 0 or x >= self.size_x or y < 0 or y >= self.size_y:
			return None

		return self.cells[x][y]

	def set(self, cell):
		self.cells[cell.x][cell.y] = cell

		if isinstance(cell, Robber):
			self.robber = cell
		elif isinstance(cell, Cop):
			self.cops.append(cell)

	def merge_heat(self, other):
		for x in xrange(self.size_x):
			for y in xrange(self.size_y):
				self.get(x, y).heat += other.get(x, y).heat

	def diffuse2(self):
		self.diffuse_cops2()
		self.diffuse_robber()

	def diffuse_cops2(self):
		for cop in self.cops:
			heat_field = Field(self.size_x, self.size_y)
			heat_field.diffuse_from(heat_field.get(cop.x, cop.y), 4.0)
			self.merge_heat(heat_field)

	def diffuse_robber(self):
		for i in range(self.size_x):
			for j in range(self.size_y):
				cell = self.get(i, j)
				cell.heat -= 103.0 / (abs(cell.x - self.robber.x) + abs(cell.y - self.robber.y) + 1) 

	def diffuse(self):
		self.diffuse_cops()
		self.diffuse_walls()

	def diffuse_cops(self):
		for cop in self.cops:
			heat_field = Field(self.size_x, self.size_y)
			heat_field.diffuse_from(heat_field.get(cop.x, cop.y), 32.0)
			self.merge_heat(heat_field)

	def diffuse_walls(self):
		heat_field = Field(self.size_x, self.size_y)

		for x in xrange(self.size_x):
			heat_field.diffuse_from(heat_field.get(x, 0), 8.0)
			heat_field.diffuse_from(heat_field.get(x, self.size_y - 1), 8.0)

		for y in xrange(self.size_y):
			heat_field.diffuse_from(heat_field.get(0, y), 8.0)
			heat_field.diffuse_from(heat_field.get(self.size_x - 1, y), 8.0)

		self.merge_heat(heat_field)

	def diffuse_from(self, cell, heat):
		cell.heat = heat
		new_heat = heat / 2

		for neighbor in self.neighbors(cell):
			if neighbor.heat < new_heat:
				self.diffuse_from(neighbor, new_heat)

	def neighbors(self, cell):
		n1 = self.get(cell.x - 1, cell.y)
		n2 = self.get(cell.x + 1, cell.y)
		n3 = self.get(cell.x, cell.y - 1)
		n4 = self.get(cell.x, cell.y + 1)

		neighbors = []
		if n1 != None:
			neighbors.append(n1)
		if n2 != None:
			neighbors.append(n2)
		if n3 != None:
			neighbors.append(n3)
		if n4 != None:
			neighbors.append(n4)

		return neighbors

	def movable_cells(self, cell):
		movable = []

		for x in xrange(-1, 2):
			for y in xrange(-1, 2):
				c = self.get(cell.x + x, cell.y + y)
				if c != None:
					movable.append(c)

		return movable

	def move(self):
		movable = self.movable_cells(self.robber)
		best = None
		for cell in movable:
			if best == None or cell.heat < best.heat:
				best = cell

		return best

	def moveCop(self, cop):
		neighbors1 = self.neighbors(Cop(cop[0],cop[1]))
		best = None
		for cell in neighbors1:
			if best == None or cell.heat < best.heat:
				best = cell
		return best

# Tail starts here
player = raw_input()
pos = [int(i) for i in raw_input().split()]
next_move(player, pos[0:2], pos[2:4], pos[4:6], pos[6:8])
